package com.xysd.express.adapter.map;

import android.content.Context;
import android.support.annotation.LayoutRes;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.xysd.express.R;
import com.xysd.express.bean.map.SearchModel;


/**
 * Created by XYSD005 on 2017/7/6.
 */

public class searchAdapter extends BaseQuickAdapter<SearchModel, BaseViewHolder> {

    private int index;
    private int resIndex;
    private Context context;

    public searchAdapter(@LayoutRes int layoutResId, Context context, int resIndex) {
        super(layoutResId);
        this.context = context;
        this.resIndex = resIndex;
    }

    public void onrefresh(int index) {
        this.index = index;
        notifyDataSetChanged();
    }

    @Override
    protected void convert(final BaseViewHolder helper, final SearchModel item) {
        helper.setText(R.id.searchName, item.getSearchAdress())
                .setText(R.id.detaliName, item.getSearchName());
        helper.getView(R.id.itemLayout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (call != null)
                    call.itemClick(item);
            }
        });
        if (resIndex == 0) {
            if (helper.getLayoutPosition() == 0) {
                helper.setTextColor(R.id.searchName, context.getResources().getColor(R.color.orange));
                helper.setTextColor(R.id.detaliName, context.getResources().getColor(R.color.orange));
            } else {
                helper.setTextColor(R.id.searchName, context.getResources().getColor(R.color.black));
                helper.setTextColor(R.id.detaliName, context.getResources().getColor(R.color.black));
            }
        }
    }


    private itemCall call;

    public void setCall(itemCall call) {
        this.call = call;
    }

    public interface itemCall {
        void itemClick(SearchModel item);
    }
}
